package cfca.seal.web.action.directive;

import cfca.seal.util.DirectiveUtil;
import freemarker.core.Environment;
import freemarker.template.ObjectWrapper;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import java.io.IOException;
import java.util.Map;
import org.springframework.stereotype.Component;

@Component
public class PageDirective
  implements TemplateDirectiveModel
{
  public static final String FORM_ID = "formid";
  public static final String URI = "uri";

  public void execute(Environment env, Map map, TemplateModel[] params, TemplateDirectiveBody arg3)
    throws TemplateException, IOException
  {
    String formId = DirectiveUtil.getString("formid", map);
    String uri = DirectiveUtil.getString("uri", map);

    env.setVariable("uri", ObjectWrapper.DEFAULT_WRAPPER.wrap(uri));
    env.setVariable("formid", ObjectWrapper.DEFAULT_WRAPPER.wrap(formId));
    env.include("ftl/defined/page.ftl", "UTF-8", true);
  }
}